home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / asm_msc1.arc / BASMAIN.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-11-20  |  2.9 KB  |  97 lines

  1. extrn    $$main:far
  2. cseg    segment para public 'code'
  3. ; Copyright 1983 Data Base Decisions
  4.  
  5. ; This program is used to set the PSP address for a compiled BASIC program.
  6. ; The PSP segment is saved at 0:4F2H.
  7.  
  8. ; It can also be used to limit the maximum memory available to a compiled
  9. ; BASIC program. The option '/M:nnn' is used on the command line, where
  10. ; nnn is the number of K-bytes the program is limited to. If no, /M option
  11. ; is specified, no memory limitation takes place. For example, '/M:64' would
  12. ; limit the program to 64*1024 bytes. The range for nnn is 64 to 1024.
  13.  
  14. ; This routine gets control before BASIC, does its handiwork, and then
  15. ; passes control to the BASIC program. It must be linked as follows:
  16. ; LINK BASMAIN+yourprog,yourprog,NUL.MAP,BASCOM
  17.  
  18. ; If BASMAIN is unable to limit memory as requested, a message is displayed
  19. ; and the execution of the program is continued.
  20.  
  21. public    basmain
  22. basmain proc far
  23.     assume cs:cseg,ds:cseg,ss:nothing,es:nothing
  24.  
  25.     push ds         ; save ds
  26.     xor ax,ax        ; make it zero
  27.     mov ds,ax        ; ds=0
  28.     mov si,4f2h        ; dos communications area
  29.     mov ax,es        ; get psp segment
  30.     mov [si],ax        ; save psp in dos comm area
  31.     pop ds            ; restore ds
  32.  
  33.     mov si,80h        ; point to command line
  34.     mov ch,0
  35.     mov cl,[si]        ; get length of command line
  36. p010:    inc si
  37.     mov al,[si]        ; get char from command line
  38.     cmp al,'/'              ; is it a slash?
  39.     jnz p020        ; no
  40.     mov ax,[si+1]        ; get next 2 chars
  41.     cmp ax,':M'             ; is it M: ?
  42.     jz p030         ; yes
  43.     cmp ax,':m'             ; is it m: ?
  44.     jz p030         ; yes
  45.  
  46. p020:    loop p010        ; check next char
  47.     jmp p080        ; no /m: or /M: found
  48.  
  49. p030:                ; found /m: or /M:
  50.     add si,3        ; point to first number
  51.     mov ax,0
  52.     mov bx,0
  53.     mov cx,10
  54. p040:    mov bl,[si]        ; get character
  55.     cmp bl,'0'              ; out of range?
  56.     jb p050         ; yes
  57.     cmp bl,'9'              ; out of range?
  58.     ja p050         ; yes
  59.     sub bl,'0'              ; convert to binary
  60.     mul cx            ; multiply ax by 10
  61.     add ax,bx        ; add new digit
  62.     inc si            ; point to next char
  63.     jmp p040        ; continue
  64.  
  65. p050:                ; got value in ax
  66.     cmp ax,64        ; less than 64K?
  67.     jb p060         ; yes - print msg
  68.     cmp ax,1024        ; greater than 1024K?
  69.     ja p060         ; yes - print msg
  70.     mov cl,6
  71.     sal ax,cl        ; convert from KB to paragraphs (*64)
  72.     mov bx,es        ; get psp
  73.     add bx,ax        ; new top of memory
  74.     mov si,2        ; point to top of memory in psp
  75.     mov ax,[si]        ; get current top of memory
  76.     cmp ax,bx        ; is new setting larger?
  77.     jae p055        ; no
  78.     mov dx,offset msg2    ; yes - print msg
  79.     jmp p065
  80.  
  81. p055:    mov [si],bx        ; save new top of memory
  82.     jmp p080
  83.  
  84. p060:    mov dx,offset msg1    ; print the message
  85. p065:    add dx,100h        ; fudge for the psp
  86.     mov ah,9
  87.     int 21h
  88.  
  89. p080:    jmp $$main        ; jump to BASIC's start point
  90.  
  91. msg1    db 'Memory specification must be from 64 to 1024',7,10,13,'$'
  92. msg2    db 'Unable to limit memory',7,10,13,'$'
  93.  
  94. basmain endp
  95. cseg    ends
  96. end    basmain         ; must be a main program!
  97.